<?php
/*
 * @Author: 天羽落星辰
 * @Date: 2020-08-16 20:53:32
 * @LastEditors: 天羽落星辰
 * @LastEditTime: 2020-08-16 22:57:34
 * @Description: file content
 */

namespace addons\nozzle;

use app\common\library\Menu;
use think\Addons;
use think\Request;

/**
 * 插件
 */
class Nozzle extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'nozzle',
                'title'   => 'API接口管理',
                'icon'    => 'fa fa-magic',
                'sublist' => [
                    [
                        'name'    => 'nozzle/empower',
                        'title'   => '授权管理',
                        'icon'    => 'fa fa-table',
                        'sublist' => [
                            ['name' => 'nozzle/empower/index', 'title' => '查看'],
                            ['name' => 'nozzle/empower/detail', 'title' => '详情'],
                            ['name' => 'nozzle/empower/change', 'title' => '变更'],
                            ['name' => 'nozzle/empower/del', 'title' => '删除'],
                            ['name' => 'nozzle/empower/multi', 'title' => '批量更新'],
                        ]
                    ],
                    [
                        'name'    => 'nozzle/empower_log',
                        'title'   => '授权日志管理',
                        'icon'    => 'fa fa-table',
                        'sublist' => [
                            ['name' => 'nozzle/empower_log/index', 'title' => '查看'],
                            ['name' => 'nozzle/empower_log/detail', 'title' => '详情'],
                            ['name' => 'nozzle/empower_log/del', 'title' => '删除'],
                        ]
                    ],
                ]
            ]
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("nozzle");
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable("nozzle");
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable("nozzle");
        return true;
    }


    /**
     * 会员中心边栏后
     * @return mixed
     * @throws \Exception
     */
    public function userSidenavAfter()
    {
        $request = Request::instance();
        $controllername = strtolower($request->controller());
        $actionname = strtolower($request->action());
        $config = get_addon_config('nozzle');
        $sidenav = explode(',', $config['usersidenav']);
        if (!$sidenav) {
            return '';
        }


        $data = [
            'controllername' => $controllername,
            'actionname'     => $actionname,
            'sidenav'        => $sidenav
        ];

        


        return $this->fetch('view/hook/user_sidenav_after', $data);
    }

   


    

}
